package com.wasai.action;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.wasai.domain.User;
import com.wasai.service.UserService;

@SuppressWarnings("serial")
@Controller
@Namespace("/user")
@Scope("prototype")
public class UserAction extends BaseAction{
	/**
	 * 
	 */
	private User user = new User();
	@Resource
	private UserService userService;
	/**
	 * 
	 * @return
	 */
	@Action(value = "detail", results = {
			@Result(location = "user.detail", type = "tiles", name = "success"),
			@Result(location = "error", type = "tiles", name = "error") })
	public final String detail() {
		String userid = ServletActionContext.getRequest().getParameter("id");
		if (userid == null) {
			return ERROR;
		} else {
			this.user = this.userService.getUserById(Integer.parseInt(userid));
		}
		if (this.user != null) {
			this.setTitle(this.user.getName());
			return SUCCESS;
		} else {
			return ERROR;
		}
	}
	/***
	 * 
	 * @return
	 */
	public final User getUser() {
		return this.user;
	}
}
